package com.example.shopfour.application;


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.shopfour.R;

import java.io.InputStream;
import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.Arrays;

public class Goods {
    private ArrayList<Bitmap> bitmaps;
    private String goodsName;
    private String describe;
    private ArrayList<String> tags;
    private int price;

    public static ArrayList<Goods> GOODSLIST =new ArrayList<>();
    public static Goods DEULT_GOODS = new Goods();

    public Goods(){
        this.bitmaps = new ArrayList<>();
        this.goodsName = "";
        this.describe = "";
        this.tags = new ArrayList<>();
        this.price = -1;
    }

    public Goods(String goodsName, String describe, String[] tags, int price){
        this();
        this.goodsName = goodsName;
        this.describe = describe;
        this.price = price;
        this.tags.addAll(Arrays.asList(tags));
    }

    public ArrayList<Bitmap> getBitmaps() {
        return bitmaps;
    }

    public void setBitmaps(ArrayList<Bitmap>  bitmaps) {
        this.bitmaps = bitmaps;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    public ArrayList<String> getTags() {
        return tags;
    }

    public void setTags(ArrayList<String> tags) {
        this.tags = tags;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public boolean equals(Goods goods){
        return this.getGoodsName().equals(goods.getGoodsName())
                && this.getTags().equals(goods.getTags())
                && this.getDescribe().equals(goods.getDescribe())
                && this.getPrice() == goods.getPrice();
    }

    public static String toPriceString(int price){
        StringBuffer sb = new StringBuffer(String.valueOf(price));
        //小于2位数
        if (sb.length()<=2)
        {
            if (sb.length() == 0){
                sb.insert(0,"0.00");
            } else if(sb.length() == 1){
                sb.insert(0,"0.0");
            } else if(sb.length() == 2){
                sb.insert(0,"0.");
            }
        } else {
            sb.insert(sb.length()-2,'.');
        }
        return sb.toString();
    }

    public static void getDefaultGoodsList(Context context){

        GOODSLIST.clear();
        Goods goods1 = new Goods("Lenovo/联想Y7000P-i7笔记本电脑游戏本15寸","易携带/混合模式/高功率",new String[]{"电脑","游戏本"},980000);
        goods1.setDescribe("发货速度快，高精度触摸屏，超薄，高待机时间，丝滑运行");
        Goods goods2 = new Goods("华为MateBook D16","轻松办公",new String[]{"电脑","轻薄本"},659900);
        goods2.setDescribe("高待机时间，丝滑办公，长时间待机，顶级续航");
        Goods goods3 = new Goods("牧马人机械手感键盘鼠标套装","高性价比/机械手感",new String[]{"鼠标","键盘"},19900);
        goods3.setDescribe("高性价比 极致机械手感");
        Goods goods4 = new Goods("Razer雷蛇旋风黑鲨","7.1环绕立体声",new String[]{"电脑配件","耳机"},26900);
        goods4.setDescribe("7.1环绕立体声，极致享受");

        ArrayList<Bitmap> bitmaps1 = new ArrayList<>();
        bitmaps1.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.mo_picture));
        goods1.setBitmaps(bitmaps1);

        ArrayList<Bitmap> bitmaps2 = new ArrayList<>();
        bitmaps2.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.key_picture));
        goods2.setBitmaps(bitmaps2);

        ArrayList<Bitmap> bitmaps3 = new ArrayList<>();
        bitmaps3.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.heat_picture));
        goods3.setBitmaps(bitmaps3);

        ArrayList<Bitmap> bitmaps4 = new ArrayList<>();
        bitmaps4.add(BitmapFactory.decodeResource(context.getResources(), R.drawable.pillow_picture));
        goods4.setBitmaps(bitmaps4);


        GOODSLIST.add(goods1);
        GOODSLIST.add(goods2);
        GOODSLIST.add(goods3);
        GOODSLIST.add(goods4);
    }

}
